
//Base on a script by Paul McFedries 
var DSLsecs
var DSLtimerID = null
var DSLtimerRunning = false
var DSLdelay = 1000
var DSLmintime = 60
var DSLMessage = '1 minute remaining!!!'
var DSLAction=1
var DSLObject=null
var DSLActionExecuted = 0
var DSLTimeOutText='Session timeout!!!'

function DSLInitializeTimer(pAction,pSecs,pMin,pMessage,pTimeoutText)
{
    DSLAction = pAction
    DSLsecs = pSecs
    DSLmintime = pMin
    DSLMessage = pMessage
    DSLTimeOutText = pTimeoutText
    DSLObject=document.getElementById('DSLSessionTimeOutCounter')
		if(DSLObject) DSLSetInnerText(DSLObject,'')
    DSLStopTheClock()
    DSLStartTheTimer()
}

function DSLStopTheClock()
{
    if(DSLtimerRunning)
        clearTimeout(DSLtimerID)
    DSLtimerRunning = false
}

function DSLStartTheTimer()
{
	var oMsg1=null
	var oMsg2=null
	var oMsg1_counter=null
    if (DSLsecs<=DSLmintime && DSLsecs>0 && DSLActionExecuted==0)
    {
        DSLActionExecuted=1
        DSLDoStep()
        switch(DSLAction){
			case 1: oMsg1=document.getElementById('DSLMessageTemplate')
					if(oMsg1) {DSLSetTopToScroll(oMsg1);oMsg1.style.visibility="visible"}
					else alert(DSLMessage)
					break
			case 2: oMsg1=document.getElementById('DSLMessageTemplate')
					if(oMsg1) {DSLSetTopToScroll(oMsg1);oMsg1.style.visibility="visible"}
					else if(confirm(DSLMessage)) __doPostBack('DSNocontrol','')
					break
			case 3: DSLStopTheClock()
					__doPostBack('DSNocontrol','')
					break
			default:
					DSLStopTheClock()
					DSLObject=document.getElementById('DSLSessionTimeOutCounter')
					if(DSLObject) DSLSetInnerText(DSLObject,'Error!!!')
		}
    }
    else if (DSLsecs<=0){
		DSLStopTheClock()
		DSLObject=document.getElementById('DSLSessionTimeOutCounter')
		if(DSLObject) DSLSetInnerText(DSLObject,DSLTimeOutText)
		oMsg1_counter=document.getElementById('DSLMessageTemplate_counter')
		if(oMsg1_counter) DSLSetInnerText(oMsg1_counter,DSLTimeOutText)
		if(DSLAction==1 || DSLAction==2){
			oMsg1=document.getElementById('DSLMessageTemplate')
			if(oMsg1) {oMsg1.style.visibility="hidden"}
			oMsg2=document.getElementById('DSLMessageTemplateExpired')
			if(oMsg2) {DSLSetTopToScroll(oMsg2);oMsg2.style.visibility="visible"}
		}
		
    }
    else
    {
		DSLDoStep()
    }
}

function DSLDoStep()
{
		var oMsg1_counter
		var strTime = DSLCheckTime(Math.floor(DSLsecs/60))+':'+DSLCheckTime(DSLsecs % 60)
		DSLObject=document.getElementById('DSLSessionTimeOutCounter')
		if(DSLObject) DSLSetInnerText(DSLObject,strTime)
		oMsg1_counter=document.getElementById('DSLMessageTemplate_counter')
		if(oMsg1_counter) DSLSetInnerText(oMsg1_counter,strTime)
	    DSLsecs = DSLsecs - 1
        DSLtimerRunning = true
        DSLtimerID = self.setTimeout("DSLStartTheTimer()", DSLdelay)
}

function DSLCheckTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}

function DSLSetTopToScroll(objref){
var ie=document.all && !window.opera
var iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
var docheight=(ie)? iebody.clientHeight: window.innerHeight
var docwidth=(ie)? iebody.clientWidth : window.innerWidth
var objheight=objref.offsetHeight
var objwidth=objref.offsetWidth
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
objref.style.top=scroll_top+docheight/2-objheight/2+"px"
objref.style.left=docwidth/2-objwidth/2+"px"
}

function DSLSetInnerText(objref,oText){
	var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false
	if(hasInnerText) {objref.innerText=oText;}
	else {objref.textContent=oText;}
}
